package edu.yctc.manage.service.impl;

import edu.yctc.manage.dao.ScoreDAO;
import edu.yctc.manage.entity.PageDO;
import edu.yctc.manage.entity.ScoreDO;
import edu.yctc.manage.service.ScoreService;
import edu.yctc.manage.utils.PageQuery;
import edu.yctc.manage.utils.VOUtil;
import edu.yctc.manage.vo.ScoreVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * @ClassName ScoreServiceImpl
 * @Description TODO
 * @Author zyj
 * @Date 2021/3/31 16:41
 * @Version 1.0
 **/
@Service
public class ScoreServiceImpl implements ScoreService {

    @Resource
    private ScoreDAO scoreDAO;

    @Autowired
    private VOUtil voUtil;

    @Override public int update(ScoreDO scoreDO) {
        return scoreDAO.update(scoreDO);
    }

    @Override public int delete(Long[] ids) {
        return scoreDAO.deleteBatchIds(Arrays.asList(ids));
    }

    @Override public int save(ScoreDO scoreDO) {
        return scoreDAO.insert(scoreDO);
    }

    @Override public PageDO getScoreVOList(PageQuery pageQuery) {
        List<ScoreVO> scoreVOS = voUtil.ScoreDOs2VOs(scoreDAO.getScoreDOs(pageQuery));
        int total = scoreDAO.getTotal();
        return new PageDO(total, pageQuery.getLimit(), pageQuery.getPage(), scoreVOS);
    }
}
    